package com.xiangban.data_platform.service;

import com.xiangban.data_platform.domain.User;
import com.xiangban.data_platform.mapper.AlternatelyMapper;
import com.xiangban.data_platform.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * @Author Mr. Ma
 * @Data 2020/11/26 10:19
 */
@Service
public class AlternatelyService {
    @Autowired
    private AlternatelyMapper alternatelyMapper;

    @Autowired
    private UserMapper userMapper;

    /**
     *  添加
     */
    public int platformsave(User user) {
        User byphone = userMapper.findByPhone(user);//通过手机号和平台查询出的sql语句。
        if (byphone!=null){
            return -1;
        }
            Date date = new Date();
            user.setCreateTime(date);
            return alternatelyMapper.platformsave(user);
    }

    /**
     * 删除
     */
    public int platformdelete(User user){
        int platformdelete = alternatelyMapper.platformdelete(user);
        return platformdelete;


    }

    /**
     *      修改
     * @param user
     * @return
     */
    public int platformupdate(User user){
        User byPhone = userMapper.findByPhone(user);
        if (byPhone!=null){
            if (byPhone.getUserid().equals(user.getUserid())){
                int platformupdate = alternatelyMapper.platformupdate(user);
                return platformupdate;
            }
            return -1;
        }
//        User byidcard = userMapper.findByidcard(user);//通过userid查询，以防是只带来要修改项。
//        if (byidcard != null){
//            if (byPhone.getUserid().equals(user.getUserid())){
//                int platformupdate = alternatelyMapper.platformupdate(user);
//                return platformupdate;
//            }
//            return -1;
//        }
        int platformupdate = alternatelyMapper.platformupdate(user);
        return platformupdate;
    }

}

